package view;

import model.Task;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Student
 * Date: 30/11/12
 * Time: 09:50
 * To change this template use File | Settings | File Templates.
 */
public class TeamPanel extends JPanel {
    public TeamPanel(String name, Color color, List<Task> backlog, List<List<Task>> progress, List<Task> done, List<Integer> dices) {
        setLayout(new GridBagLayout());
        TitledBorder border = BorderFactory.createTitledBorder(name);
        border.setTitleColor(color);
        setBorder(border);
        int max = maxListSize(progress);
        int sideColumnMax = backlog.size() > done.size() ? backlog.size() : done.size();
        if(sideColumnMax > max) {
            max = sideColumnMax;
        } else {
            max++;
        }
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridwidth = 8;
        constraints.weightx = 1;
        add(new DicePanel(dices), constraints);
        constraints.fill = GridBagConstraints.BOTH;
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.gridwidth = 1;
        constraints.weightx = 1;
        add(new ColumnPanel("Backlog", color, backlog, max), constraints);
        constraints.gridx = 1;
        constraints.gridwidth = 1;
        constraints.weightx = 6;
        add(new ProgressPanel("In Progress", color, progress, max - 1), constraints);
        constraints.gridx = 2;
        constraints.gridwidth = 1;
        constraints.weightx = 1;
        add(new ColumnPanel("Done", color, done, max), constraints);
        setBackground(Color.white);
    }

    private int maxListSize(List<List<Task>> lists) {
        int max = 0;
        int size;
        for (List list : lists) {
            size = list.size();
            max = size > max ? size : max;
        }
        return max;
    }
}
